package br.com.onlinebidding.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(schema = "db_onlinebidding", name = "User")
@NamedQuery(name = "User.findUserByEmail", query = "select u from User u where u.email = :email")
public class User implements Serializable {
	
	private static final long serialVersionUID = 1L;
	public static final String FIND_BY_EMAIL = "User.findUserByEmail";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Column(unique = true)
	private String name;
	private String password;
	private String email;
	private String profile;
	private String numberRegistration;
	private int telephone;

	public int getId() {return this.id;}
	public void setId(int id) {this.id = id;}
	
	public boolean isAdmin() {return getProfile().equalsIgnoreCase("admin");}

	public boolean isUser() {return getProfile().equalsIgnoreCase("fornecedor");}

	public String getProfile() {return this.profile;}
	public void setProfile(String profile) {this.profile = profile;}

	public String getNumberRegistration() {return this.numberRegistration;}
	public void setNumberRegistration(String numberRegistration) {this.numberRegistration = numberRegistration;}

	public int getTelephone() {return this.telephone;}
	public void setTelephone(int telephone) {this.telephone = telephone;}

	public String getEmail() {return this.email;}
	public void setEmail(String email) {this.email = email;}

	public String getPassword() {return this.password;}
	public void setPassword(String password) {this.password = password;}

	public String getName() {return this.name;}
	public void setName(String name) {this.name = name;}

	@Override
	public int hashCode() {return getId();}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof User) {
			User user = (User) obj;
			return user.getId() == this.id;}
		return false;
	}
}